package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Api(tags = "护理项目管理相关接口")
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @ApiOperation("分页查询护理列表接口")
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
           @ApiParam("护理项目名字") String name ,
           @ApiParam("当前页码") @RequestParam(defaultValue = "1") Integer pageNum ,
           @ApiParam("每页显示条数") @RequestParam(defaultValue = "10") Integer pageSize ,
           @ApiParam("状态 0禁用 1启动") Integer status
    ){
        log.info("查询护理项目列表name={},pageNum={},pageSize={},status={}", name , pageNum , pageSize ,status);
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getByPage(name , pageNum , pageSize , status);
        return ResponseResult.success(pageResponse) ;
    }

    /**
     * 新增护理项目
     * @param nursingProjectDto
     * @return
     */
    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult add(
       @ApiParam(value = "护理项目数据传输对象") @RequestBody NursingProjectDto nursingProjectDto
    ){
        nursingProjectService.add(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理项目
     * @param id 护理项目id
     * @return
     */
    @ApiOperation("删除护理项目接口")
    @DeleteMapping("/{id}")
    public ResponseResult deleteProject(
            @ApiParam(value = "护理项目id")
            @PathVariable Long id
    ){
        nursingProjectService.deleteProject(id);
        return ResponseResult.success();
    }

    /**
     * 根据id查询护理项目
     * @param id
     * @return
     */
    @ApiOperation("根据id查询护理项目")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(
       @ApiParam("传入ID参数")  @PathVariable Long id
    ) {

        return ResponseResult.success( nursingProjectService.getById(id));
    }

    /**
     * 修改护理项目
     * @param nursingProjectDto
     * @return
     */
    @ApiOperation("修改护理项目")
    @PutMapping
    public ResponseResult update(
           @RequestBody NursingProjectDto nursingProjectDto
    ){
        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 查询所有护理项目
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult getAllProject(){
        List<NursingProjectVo> projectVos =  nursingProjectService.getAllProject();
        return ResponseResult.success(projectVos);
    }

    /**
     * 护理项目的禁用启用
     * @param id 护理项目id
     * @param status 护理项目状态
     * @return
     */
    @ApiOperation("护理项目的禁用启用接口")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(
            @ApiParam(value = "护理项目id")
            @PathVariable Long id,
            @ApiParam
            @PathVariable Integer status
    ){
        nursingProjectService.updateStatus(id,status);
        return ResponseResult.success();
    }

}
